<template>
    <div>
        <a-card :bordered="false">
            <div class="table-page-search-wrapper">
                <a-form layout="horizontal" :label-col="auditLabelCol" :wrapper-col="auditWrapperCol">
                    <a-row :gutter="8">
                        <!--
                        <a-col :md="4" :sm="24">
                            <a-form-item label="统筹区">
                                <a-select placeholder="请选择" allowClear v-model="queryParam.areaCode">
                                    <a-select-option v-for="item in dictData.areaCode" :key="item.dictKey" :value="item.dictKey">{{ item.dictValue }}</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        -->
                        <a-col :span="6">
                            <a-form-item label="姓名">
                                <a-input v-model="queryParam.fullName"/>
                            </a-form-item>
                        </a-col>
                        <a-col :span="6">
                            <a-form-item label="证件类型">
                                <a-select placeholder="请选择" allowClear v-model="queryParam.cardType">
                                    <a-select-option v-for="item in dictData.cardType" :key="item.dictKey"
                                                     :value="item.dictKey">{{ item.dictValue }}
                                    </a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :span="6">
                            <a-form-item label="证件号码">
                                <a-input v-model="queryParam.idcard"/>
                            </a-form-item>
                        </a-col>
                        <template v-if="advanced">
                            <a-col :span="6">
                                <a-form-item label="国家">
                                    <a-select show-search option-filter-prop="children" placeholder="请选择" allowClear v-model="queryParam.country">
                                        <a-select-option v-for="item in dictData.country" :key="item.dictKey"
                                                         :value="item.dictKey">{{ item.dictValue }}
                                        </a-select-option>
                                    </a-select>
                                </a-form-item>
                            </a-col>
                            <a-col :span="6">
                                <a-form-item label="工作单位">
                                    <a-input v-model="queryParam.orgName"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="6">
                                <a-form-item label="最高学历">
                                    <a-select mode="multiple" placeholder="请选择" allowClear v-model="queryParam.educationTypeList">
                                        <a-select-option v-for="item in dictData.educationType" :key="item.dictKey"
                                                         :value="item.dictKey">{{ item.dictValue }}
                                        </a-select-option>
                                    </a-select>
                                </a-form-item>
                            </a-col>
                            <a-col :span="6">
                                <a-form-item label="所学专业">
                                    <a-select show-search option-filter-prop="children" placeholder="请选择" allowClear v-model="queryParam.major">
                                        <a-select-option v-for="item in dictData.major" :key="item.dictKey"
                                                         :value="item.dictKey">{{ item.dictValue }}
                                        </a-select-option>
                                    </a-select>
                                </a-form-item>
                            </a-col>
                            <a-col :span="6">
                                <a-form-item label="本地人才等级">
                                    <a-select mode="multiple" placeholder="请选择" allowClear v-model="queryParam.localLevelList">
                                        <a-select-option v-for="item in dictData.talentLevel" :key="item.dictKey"
                                                         :value="item.dictKey">
                                            {{ item.dictValue }}
                                        </a-select-option>
                                    </a-select>
                                </a-form-item>
                            </a-col>
                            <a-col :span="6">
                                <a-form-item label="人才层级">
                                    <a-select placeholder="请选择" allowClear v-model="queryParam.talentRank">
                                        <a-select-option v-for="item in dictData.talentRank" :key="item.dictKey"
                                                         :value="item.dictKey">
                                            {{ item.dictValue }}
                                        </a-select-option>
                                    </a-select>
                                </a-form-item>
                            </a-col>
                        </template>
                        <a-col :span="6">
                            <span class="table-page-search-submitButtons"  :md="!advanced && 8 || 24" :sm="24">
                                <a-button type="primary" @click="() =>{this.findListBtn()}">查询</a-button>
                                <a-button @click="() =>{this.addBtn()}">新增</a-button>
                                <a @click="toggleAdvanced" style="margin-left: 8px">
                                    {{ advanced ? '收起' : '展开' }}
                                    <a-icon :type="advanced ? 'up' : 'down'"/>
                                </a>
                            </span>
                        </a-col>
                    </a-row>
                </a-form>
            </div>
            <vxe-grid
                    class="vxe-table-antd"
                    resizable
                    show-overflow
                    ref="listTable"
                    stripe
                    border
                    highlight-hover-row
                    highlight-current-row
                    highlight-hover-column
                    highlight-current-column
                    highlight-cell
                    height="500"
                    :data="tableData"
                    :start-index="(tablePage.currentPage - 1) * tablePage.pageSize"
                    :pager-config="tablePage"
                    @page-change="handlePageChange"
                    >
                <vxe-table-column type="seq" width="80" fixed="left" align="center" title="序号"></vxe-table-column>
                <vxe-table-column field="fullName" title="姓名" width="100" align="center"/>
                <vxe-table-column field="cardTypeName" title="证件类型" width="100" align="center"/>
                <vxe-table-column field="idcard" title="证件号码" width="100" align="center"/>
                <vxe-table-column field="sexName" title="性别" width="100" align="center"/>
                <vxe-table-column field="birthday" title="出生日期" width="100" align="center"/>
                <vxe-table-column field="countryName" title="国家" width="100" align="center"/>
                <vxe-table-column field="orgName" title="工作单位" width="100" align="center"/>
                <vxe-table-column field="educationName" title="最高学历" width="100" align="center"/>
                <vxe-table-column field="majorName" title="所学专业" width="100" align="center"/>
                <vxe-table-column field="workStatusName" title="在职状态" width="100" align="center"/>
                <vxe-table-column field="userTitle" title="头衔称号" width="100" align="center"/>
                <vxe-table-column field="localLevel" title="本地人才等级" width="100" align="center"/>
                <vxe-table-column field="cellphone" title="手机号" width="100" align="center"/>
                <vxe-table-column field="talentRank" title="人才层级" width="100" align="center"/>
                <vxe-table-column field="contactCityValue" title="联系地 市" width="100" align="center"/>
                <vxe-table-column
                        field="operation"
                        title="操作"
                        fixed="right"
                        width="200"
                        align="center"
                        show-overflow>
                    <template v-slot="{ row }">
                        <a-button @click="queryDetail(row)">详细信息</a-button>
                        <a-button type="primary" @click="modifyDetail(row)">修改</a-button>
                    </template>
                </vxe-table-column>
            </vxe-grid>
        </a-card>
        <a-modal destroyOnClose width="80%" v-model="windowVisible" title="信息查看页面" :footer="null">
            <talent-query-form ref="talentQueryPage" :personId="personId" />
        </a-modal>
        <a-modal destroyOnClose width="80%" v-model="editVisible" title="信息修改页面"
                 @ok="pdSave"
                 cancelText="取消"
                 okText="保存">
            <talent-edit-form ref="talentEditPage" :personId="personId" />
        </a-modal>
    </div>

</template>

<script>
    import {getBatchDict} from "@/services/system/api"
    import {queryTalentList} from "@/services/system/abs"
    import talentQueryForm from "@/pages/overview/TalentQueryForm"
    import talentEditForm from "@/pages/overview/TalentEditForm"
    import {addOrEditPerson} from "@/services/system/abs"
    import moment from 'moment'

    export default {
        name: "TalentPersonInfoModify",
        components:{
            talentQueryForm,
            talentEditForm
        },
        data() {
            return {
                advanced: false,
                // 查询参数
                queryParam: {
                    areaCode: '',
                    fullName: '',
                    cardType: '',
                    idcard: '',
                    degreeType: '',
                    educationTypeList: [],
                    birthday:'',
                    country:'',
                    orgName:'',
                    major:'',
                    localLevelList:[],
                    talentRank:'',
                    pageNum:'',
                    pageSize:''

                },
                tableData: [],

                dictData: [],
                auditLabelCol: {
                    xs: {span: 24},
                    sm: {span: 7}
                },
                auditWrapperCol: {
                    xs: {span: 24},
                    sm: {span: 17}
                },
                personId:null,
                windowVisible:false,
                editVisible:false,
                tablePage: {
                    total: 0,
                    currentPage: 1,
                    pageNum: 1,
                    pageSize: 20
                }
            }
        },
        created() {
            // 数据初始化
            // 数据字典初始化
            const params = {}
            params.dictFields = 'talentRank,areaCode,cardType,degreeType,educationType,sex,country,educationType,major,talentLevel'
            this.$http.post(getBatchDict, params).then(res => {
                this.dictData = res.result
            })
        },
        methods: {
            findListBtn() {
                this.tablePage.pageNum = 1
                this.tablePage.currentPage = 1
                this.workQuerylList()
            },
            queryDetail(row) {
                this.personId=row.personId
                this.windowVisible = true
            },
            modifyDetail(row){
                this.personId=row.personId
                this.editVisible = true
            },
            addBtn(){
                this.personId=null;
                this.editVisible = true
            },
            //改变当前页
            handlePageChange ({ currentPage, pageSize }) {
                this.tablePage.pageNum = currentPage
                this.tablePage.currentPage = currentPage
                this.tablePage.pageSize = pageSize
                this.workQuerylList()
            },
            //查询待办事项
            workQuerylList(){
                this.queryParam.pageNum=this.tablePage.pageNum;
                this.queryParam.pageSize=this.tablePage.pageSize;
                this.tablePage.total=1;

                this.$http.post(queryTalentList, this.queryParam).then((res) => {
                    this.tableData= res.result.list;
                    this.tablePage.total=res.result.total;
                }).catch(() => {

                })
            },
            //展开和收起
            toggleAdvanced () {
                this.advanced = !this.advanced
            },
            pdSave(){
                const editPage=this.$refs.talentEditPage
                const vo=editPage.newFormData

                if(vo.cardDateStart!=null){
                    vo.cardDateStart=moment(vo.cardDateStart).format('YYYYMMDD')
                }
                if(vo.cardDateEnd!=null){
                    vo.cardDateEnd=moment(vo.cardDateEnd).format('YYYYMMDD')
                }
                if(vo.birthday!=null){
                    vo.birthday=moment(vo.birthday).format('YYYY-MM-DD')
                }
                if(vo.workedTime!=null){
                    vo.workedTime=moment(vo.workedTime).format('YYYY-MM-DD')
                }
                if(editPage.$refs.xGrid3!=null){
                    vo.educationList=editPage.$refs.xGrid3.getTableData().tableData
                }
                if(editPage.$refs.xGrid5!=null){
                    vo.userTitleList=editPage.$refs.xGrid5.getTableData().tableData
                }
                if(editPage.$refs.xGrid4!=null){
                    vo.workList=editPage.$refs.xGrid4.getTableData().tableData
                }

                if(vo.educationList!=null){
                    vo.educationList.forEach((item) => {
                        if(item.degreeDate!=null){
                            item.degreeDate=moment(item.degreeDate).format('YYYYMMDD');
                        }
                        if(item.endDate!=null){
                            item.endDate=moment(item.endDate).format('YYYYMMDD');
                        }
                        if(item.startDate!=null){
                            item.startDate=moment(item.startDate).format('YYYYMMDD');
                        }
                    })
                }

                if(vo.workList!=null){
                    vo.workList.forEach((item)=> {
                        if (item.contractStartDate!=null) {
                            item.contractStartDate = moment(item.contractStartDate).format('YYYYMMDD')
                        }
                        if (item.contractEndDate!=null) {
                            item.contractEndDate = moment(item.contractEndDate).format('YYYYMMDD')
                        }
                        if (item.entryTime!=null) {
                            item.entryTime = moment(item.entryTime).format('YYYY-MM-DD')
                        }
                        if (item.quitTime != null) {
                            item.quitTime = moment(item.quitTime).format('YYYY-MM-DD')
                        }
                    })
                }

                if(vo.userTitleList!=null){
                    vo.userTitleList.forEach((item)=>{
                        if(item.grantTime!=null){
                            item.grantTime=moment(item.grantTime).format('YYYY-MM-DD')
                        }
                    })
                }

                this.$http.post(addOrEditPerson, vo).then(() => {
                    this.editVisible=false;
                }).catch(() => {

                })
            }
        }
    }
</script>